﻿#include "tunnel.h"

Tunnel::Tunnel(QObject *parent) : QObject(parent)
{
    receiver=new QUdpSocket(this);
    receiver->bind(TUN_PORT,QUdpSocket::ShareAddress);
    connect(receiver,&QUdpSocket::readyRead,this,&Tunnel::processPendingDatagram);
}

void Tunnel::processPendingDatagram()
{
    while(receiver->hasPendingDatagrams())
    {
        QByteArray data;
        data.resize(receiver->pendingDatagramSize());
        receiver->readDatagram(data.data(),data.size());

        QDataStream in(&data,QIODevice::ReadOnly);
        in >> title >> content ;
        emit received();
    }
}
